﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IsmsExplorer.Infrastructure.DomainBase;

namespace IsmsExplorer.Model.Documents {
    public class IsmsDocumentLink : EntityBase {
        private Guid _documentID = Guid.Empty;
        private int _repositoryTypeID;
        private string _documentName;
        private string _documentUrl;
        private string _repositoryVersion;
        private int _projectID;
        private int _documentTypeID;
        private string _description;

        /// <summary>
        /// Here we don'd make use of the base class ID (int), we have a Guid ID
        /// </summary>
        /// <param name="documentID"></param>
        public IsmsDocumentLink(Guid documentID)
            : base() {
            _documentID = documentID;
        }
        public IsmsDocumentLink()
            : this(Guid.NewGuid()) {
        }

        public override int ID {
            get {
                throw new NotImplementedException("ID Property not used! Please use the DocumentID property instead");
            }
            set {
                throw new NotImplementedException("ID Property not used! Please use the DocumentID property instead");
            }
        }

        /// <summary>
        /// Optional value (string) describing the document if not obvious what it's purpose is.
        /// By default it's null or string.Empty (both meaning "not-set").
        /// </summary>
        public string Description {
            get { return _description; }
            set { _description = value; }
        }

        /// <summary>
        /// Optional integer value >0 describing document type (e.g. Scope, SoA etc.)
        /// By default, it is assigned to 0 meaning "not-set".
        /// </summary>
        public int DocumentTypeID {
            get { return _documentTypeID; }
            set { _documentTypeID = value; }
        }

        public int ProjectID {
            get { return _projectID; }
            set { _projectID = value; }
        }

        public string RepositoryVersion {
            get { return _repositoryVersion; }
            set { _repositoryVersion = value; }
        }

        public string DocumentURL {
            get { return _documentUrl; }
            set { _documentUrl = value; }
        }

        public string DocumentName {
            get { return _documentName; }
            set { _documentName = value; }
        }

        public int RepositoryTypeID {
            get { return _repositoryTypeID; }
            set { _repositoryTypeID = value; }
        }

        public Guid DocumentID {
            get { return _documentID; }
            set { _documentID = value; }
        }

        #region Equality tests
        /// <summary>
        /// Equality based on two objects being of same type, having the same Guid and same ProjectID!
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj) {
            if (obj == null || !(obj is IsmsDocumentLink)) {
                return false;
            }
            return (this == (IsmsDocumentLink)obj);
        }

        /// <summary>
        /// Equality based on two objects being of same type, having the same Guid and same ProjectID!
        /// </summary>
        /// <param name="l"></param>
        /// <param name="r"></param>
        /// <returns></returns>
        public static bool operator ==(IsmsDocumentLink l, IsmsDocumentLink r) {
            // NOTE: need the cast, otherwise infinite loop!
            if (((object)l == null) && ((object)r == null)) {
                return true;
            }

            if (((object)l == null) || ((object)r == null)) {
                return false;
            }

            if (l.GetType() != r.GetType()) {
                return false;
            }

            if ((l.DocumentID != r.DocumentID) || (l.ProjectID != r.ProjectID)) {
                return false;
            }

            return true;
        }

        /// <summary>
        /// Equality based on two objects being of same type, having the same Guid and same ProjectID!
        /// </summary>
        /// <param name="l"></param>
        /// <param name="r"></param>
        /// <returns></returns>
        public static bool operator !=(IsmsDocumentLink l, IsmsDocumentLink r) {
            return !(l == r);
        }

        /// <summary>
        /// Hashcode depends on both DocumentID and Project ID.
        /// </summary>
        /// <returns></returns>
        public override int GetHashCode() {
            return string.Concat(_documentID, _projectID).GetHashCode();
        }

        #endregion

    }
}
